package org.dao.impl;

import org.apache.ibatis.session.SqlSessionFactory;
import org.dao.BooksDao;
import org.entity.Books;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public class BooksDaoImpl extends SqlSessionDaoSupport implements BooksDao {
    @Autowired
    @Override
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
        super.setSqlSessionFactory(sqlSessionFactory);
    }

    @Override
    public Books queryById(Integer bookid) {
        BooksDao mapper = getSqlSession().getMapper(BooksDao.class);
        return mapper.queryById(bookid);
    }

    @Override
    public List<Books> queryAllByLimit(int offset, int limit) {
        BooksDao mapper = getSqlSession().getMapper(BooksDao.class);
        return mapper.queryAllByLimit(offset, limit);
    }

    @Override
    public List<Books> queryAll(Books books) {
        BooksDao mapper = getSqlSession().getMapper(BooksDao.class);
        return mapper.queryAll(books);
    }

    @Override
    public int insert(Books books) {
        BooksDao mapper = getSqlSession().getMapper(BooksDao.class);
        return mapper.insert(books);
    }

    @Override
    public int update(Books books) {
        BooksDao mapper = getSqlSession().getMapper(BooksDao.class);
        return mapper.update(books);
    }

    @Override
    public int deleteById(Integer bookid) {
        BooksDao mapper = getSqlSession().getMapper(BooksDao.class);
        return mapper.deleteById(bookid);
    }
}
